package org.example.strategypatterndemo.module1;

import org.example.strategypatterndemo.module1.service.PromotionStrategy;
import org.springframework.stereotype.Service;

/**
 * OrderService 服务类
 * @author dingchen
 * @version 2025/05/29 12:37
**/
@Service
public class OrderService {
    private final PromotionFactory promotionFactory;

    public OrderService(PromotionFactory promotionFactory) {
        this.promotionFactory = promotionFactory;
    }


    /**
     * 计算最终价格
     * @param orderAmount 订单金额
     * @param promotionType 促销类型
     * @return 最终价格
     */
    public double calculateFinalPrice(double orderAmount, PromotionType promotionType) {

        PromotionStrategy strategy = promotionFactory.getStrategy(promotionType);

        double discount = strategy.calculateDiscount(orderAmount);

        return orderAmount - discount;
    }
}

